import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'


Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        hasLogin: false,
        userName: "",
        token: ""
    },
    getters: {
        isLogin: state => state.hasLogin,
        token: state => state.token,
        userName: state => state.userName
    },
    mutations: {
        login(state, payload) {
            state.userName = payload.userName
            state.hasLogin = true
            state.token = payload.token
        },
        logout: (state, payload) => {
            state.hasLogin = false
            state.token = null
            state.userName = ""
        }
    },
    actions: {},
    modules: {},
    plugins: [createPersistedState()]  //加上这个就可以了
})
